/*
 * @Author: wuqingchun
 * @Date: 2024-06-22 14:04:19
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-06-22 14:28:39
 */
#ifndef __HTTP_POLLER_H__
#define __HTTP_POLLER_H__

#include <sys/epoll.h>

#include "http_logger.h"
#include "http_event.h"

class CHTTPEventPoller
{
private:
    static constexpr size_t EVENT_MAX_COUNT = 1024;
    static constexpr int WAIT_TIMEOUT_MS = 10;   // epoll_wait 等待超时时间（单位为微秒）
public:
    CHTTPEventPoller(CHTTPLogger& refLogger);

    ~CHTTPEventPoller();

    int Init();

    int AddEvent(IHTTPEvent& refEvent, EEventType enType);

    int ModifyEvent(IHTTPEvent& refEvent, EEventType enType);

    int DeleteEvent(IHTTPEvent& refEvent);

    int Poll();

private:
    int __EventCtl(int iOperType, IHTTPEvent& refEvent, EEventType enType);

private:
    int m_iEpollFd = -1;
    struct epoll_event m_astEvents[EVENT_MAX_COUNT];
    CHTTPLogger& m_refLogger;
};

#endif //__HTTP_POLLER_H__